package com.yc.filter;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yc.bean.PayType;
import com.yc.biz.PayTypeBiz;
import com.yc.biz.impl.PayTypeBizImpl;

@WebFilter("/user_center_info.jsp")
public class MyFilter3 implements Filter {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest request=(HttpServletRequest) req;
		HttpServletResponse response=(HttpServletResponse) resp;
		
		PrintWriter out=response.getWriter();
		PayTypeBiz bt=new PayTypeBizImpl();
		int uid = 0;
		try {
			uid = Integer.parseInt( request.getSession().getAttribute("uid")+"" );
		} catch (NumberFormatException e) {
//			e.printStackTrace();
		}
		List<PayType> list=bt.findAll(uid);
		if(list.size()>0){
			request.getSession().setAttribute("payType", list);
		}else{
			chain.doFilter(request, response);
		}
		chain.doFilter(request, response);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {

	}

}
